package com.wofish.oauth.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.text.SimpleDateFormat;
import java.util.Date;

public class BaseController {
	
	protected final Logger log = LoggerFactory.getLogger(this.getClass());

	protected static final String SUCCESS = "success";


	protected static final String APP_ID = "wofish";

	/**
	 * 业务正常
	 */
	public static final int BUSI_NORMAL = 1;

	/**
	 * 业务异常
	 */
	public static final int BUSI_ERROR = 0;

	@InitBinder
	public void initBinder(WebDataBinder binder) {
		registCustomEditorDate(binder);
	}

	/**
	 * 时间格式绑定
	 * @param binder
     */
	private void registCustomEditorDate (WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		dateFormat.setLenient(false); // 严格检查
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	}

}
